package com.space.jwt.api;

import com.space.jwt.Dto.ManagerInfo;
import com.space.jwt.api.model.BaseResponse;
import com.space.jwt.common.util.JWTUtil;
import com.space.jwt.service.ManagerInfoService;
import com.space.jwt.shiro.MyShiroRealm;
import com.space.jwt.shiro.ShiroKit;
import io.swagger.annotations.Api;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.cache.ehcache.EhCache;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.SimplePrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 机具管理API接口类
 */
@Api(tags = "机具管理API接口类")
@RestController
@RequestMapping(value = "/api/v1")
public class PublicController {

    private static final Logger _logger = LoggerFactory.getLogger(PublicController.class);
    @Autowired
    ManagerInfoService  managerInfoService ;

    /**
     * 入网绑定查询接口
     *
     * @return 是否入网
     */
    @RequestMapping(value = "/join", method = RequestMethod.GET)
    @RequiresAuthentication
    public BaseResponse join(@RequestParam("imei") String imei) {
        _logger.info("入网查询接口 start... imei=" + imei);
        System.out.println("用户身份=="+ShiroKit.principal());
        String username  = JWTUtil.getUsername(ShiroKit.principal());
        ManagerInfo managerInfo = managerInfoService.findByUsername(username);
        BaseResponse result = new BaseResponse();
        result.setSuccess(true);
        result.setMsg("已入网并绑定了网点");
        result.setData(managerInfo);
        return result;
    }

}
